<?php
namespace Badmins\Controller;
use Think\Controller;
class SetController extends Controller {
    public function index(){
    	$list = F('web_web');
    	$this->assign('va',$list);
        $this->display();
    }
    /**
     * 保存网站信息
     */
    public function save_web(){
    	$basc = F('web_web')?F('web_web'):array();
    	$bascs = I('post.');
    	unset($basc['web_bottom']);
    	//if(!empty())
    	$bascs['web_bottoms'] = $_POST['web_bottom'];
    	$bascs['web_script'] = $_POST['web_script'];
    	$newlist = array_merge($basc, $bascs);
    	F('web_web',$newlist);
    	showmsg(200,'保存成功');
    }
    /**
     * 基本设置
     */
    public function basic(){
    	$list = F('web_web');
    	$list['upload_max'] = $list['upload_max']/1024/1024;
    	$this->assign('va',$list);
    	$this->display();
    } 
    /**
     * 保存基本设置
     */
    public function save_basic(){
    	$basc = F('web_web')?F('web_web'):array();
    	$list = I('post.');
    	$list['upload_max'] = $list['upload_max']*1024*1024;
    	$newlist = array_merge($basc, $list);
    	F('web_web',$newlist);
    	showmsg(200,'保存成功');
    }
    /**
     * 短息设置
     */
    public function sms()
    {
    	$list = F('web_web');
    	$this->assign('va',$list);
    	$this->display();
    }
    /**
     * 保存短信设置
     */
    public function save_sms(){
    	$basc = F('web_web')?F('web_web'):array();
    	$list = I('post.');
    	$newlist = array_merge($basc, $list);
    	F('web_web',$newlist);
    	showmsg(200,'保存成功');
    }
    /**
     * 购物限制
     */
    public function astrict(){
    	$list = F('web_web');
    	$this->assign('va',$list);
    	$this->display();
    }
    /**
     * 保存购物限制
     */
    public function save_shopping(){
    	$basc = F('web_web')?F('web_web'):array();
    	$list = I('post.');
    	$newlist = array_merge($basc, $list);
    	F('web_web',$newlist);
    	showmsg(200,'保存成功');
    }
    /**
     * 邮箱设置
     */
    public function email(){
    	$list = F('web_web');
    	$this->assign('va',$list);
    	$this->display();
    }
    /**
     * 保存邮箱
     */
    public function save_email(){
    	$basc = F('web_web')?F('web_web'):array();
    	$list = I('post.');
    	$newlist = array_merge($basc, $list);
    	F('web_web',$newlist);
    	$test = $_POST['test_email'];
    	if(!empty($test)){
    		if(empty($_POST['smtp']) || empty($_POST['email_account']) || empty($_POST['email_password'])){
    			showmsg('300','请输入邮箱信息');exit();
    		}
    		$a = sendemail("测试邮箱","测试邮箱，请勿回复", $test);
    		if($a){
    			showmsg(200,'发送邮箱成功');
    		}else{
    			showmsg(300,'发送邮箱失败');
    		}
    	}else{
    		showmsg(200,'保存成功');
    	}
    }
    /**
     * 水印设置
     */
    public function wmk(){
    	$list = F('web_web');
    	$this->assign('va',$list);
    	$this->display();
    }
    /**
     * 保存水印设置
     */
    public function save_wmk(){
    	$basc = F('web_web')?F('web_web'):array();
    	$list = I('post.');
    	$newlist = array_merge($basc, $list);
    	F('web_web',$newlist);
    	showmsg(200,'保存成功');
    }
    /**
     * 分销设置
     */
    public function distr(){
    	$list = F('web_web');
    	$this->assign('va',$list);
    	$this->display();
    }
    /**
     * 保存分销设置
     */
    public function save_distr(){
    	$basc = F('web_web')?F('web_web'):array();
    	$list = I('post.');
    	$newlist = array_merge($basc, $list);
    	F('web_web',$newlist);
    	showmsg(200,'保存成功');
    }
    /**
     * 快递列表
     */
    public function exp(){
    	
    	$listrow = (int)I('pageSize');
    	if(empty($listrow)){
    		$listrow = 15;
    	}
    	$p = I('pageCurrent','','intval')?I('pageCurrent','','intval'):'1';
    	$db = M('express_list');
    	//$db->where("status='0'")->setField('status',1);exit();
    	$name = I('name');
    	if(!empty($name)){
    		$where['name'] = array('like',"%{$name}%");
    	}
    	$class_id = I('status');
    	if($class_id != ""){
    		$where['status'] = $class_id;
    	}
    	$count = $db->where($where)->order("id desc")->count();
    	$list = $db->where($where)->order("status asc,id desc")->limit((($p-1)*$listrow),$listrow)->select();
    	if($count>$listrow){
    		$show['total'] = $count;
    		$show['listrow'] = $listrow;
    		$this->assign('show',$show);
    	}
    	$this->assign('list',$list);
    	$this->display();
    }
    /**
     * 友情链接
     */
    public function firend(){
    	$listrow = (int)I('pageSize');
    	if(empty($listrow)){
    		$listrow = 15;
    	}
    	$where = array();
    	$status = I('status');
    	if($status !=''){
    		$where['status'] = $status;
    	}
    	$name = I('name');
    	if(!empty($name)){
    		$where['name'] = array('like',"%{$name}%");
    	}
    	$p = I('pageCurrent/d')?I('pageCurrent/d'):'1';
    	$db = D('Common/FriendLink');
    	$count = $db->where($where)->count();
    	$firstrow = ($p-1)*$listrow;
    	$list = lists('friend_link','',$where,"*","id desc",$firstrow,$listrow,2);
        if($count>$listrow){
			$show['total'] = $count;
			$show['listrow'] = $listrow;
			$this->assign('show',$show);
		}
		$this->assign('list',$list);
    	$this->display();
    }
    /**
     * 自定义导航
     */
    public function nav(){
    	$listrow = (int)I('pageSize');
    	if(empty($listrow)){
    		$listrow = 15;
    	}
    	$p = I('pageCurrent/d')?I('pageCurrent/d'):'1';
    	//$db = D('Common/Nav');
    	$count = M('nav')->count();
    	$firstrow = ($p-1)*$listrow;
    	$list = lists('nav','',1,"*","",$firstrow,$listrow,2);
    	if($count>$listrow){
    		$show['total'] = $count;
    		$show['listrow'] = $listrow;
    		$this->assign('show',$show);
    	}
    	$list = \Org\Oa\common::sortdata($list,0);
    	$this->assign('list',$list);
    	$this->display();
    }
    /**
     * 区域
     */
    public function area(){
    	$id = I('id/d');
    	if($id){
    		$map['parent_id'] = $id;
    	}else{
    		$map['parent_id'] = 0;
    	}
    	$name = I('name');
    	if(!empty($name)){
    		$map['name'] = array('like',"%{$name}%");
    	}
    	$list = lists('region','',$map,"*","status asc,id asc",0,0,2);
    	$this->assign('list',$list);
    	$this->display();
    }
    /**
     * 城市
     */
    public function city(){
    	$id = I('id/d');
    	if($id){
    		$map['parent_id'] = $id;
    	}else{
    		$map['parent_id'] = 0;
    	}
    	$name = I('name');
    	if(!empty($name)){
    		$map['name'] = array('like',"%{$name}%");
    	}
    	$list = lists('city','',$map,"*","status asc,id asc",0,0,2);
    	$this->assign('list',$list);
    	$this->display();
    }
    /**
     * 配送方式
     */
    public function freights(){
    	$listrow = (int)I('pageSize');
    	if(empty($listrow)){
    		$listrow = 15;
    	}
    	$p = I('pageCurrent','','intval')?I('pageCurrent','','intval'):'1';
    	$db = M('delivery');
    	$name = I('name');
    	if(!empty($name)){
    		$where['name'] = array('like',"%{$name}%");
    	}
    	$class_id = I('status');
    	if($class_id != ""){
    		$where['status'] = $class_id;
    	}
    	$count = $db->where($where)->order("id desc")->count();
    	$list = $db->where($where)->order("status asc,id desc")->limit((($p-1)*$listrow),$listrow)->select();
    	if($count>$listrow){
    		$show['total'] = $count;
    		$show['listrow'] = $listrow;
    		$this->assign('show',$show);
    	}
    	$this->assign('list',$list);
    	$this->display();
    }
}


